home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 8 / Night Owl CD-ROM (NOPV8) (Night Owl Publisher) (1993).ISO / 017a / binutils.arj / AOUTENCA.H < prev    next >
C/C++ Source or Header  |  1991-03-27  |  4KB  |  139 lines

  1. /* Another try at encapsulating bsd object files in coff.
  2.    Copyright (C) 1988, 1989, Free Software Foundation, Inc.
  3.    Written by Pace Willisson 12/9/88
  4.  
  5.    This file is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 1, or (at your option)
  8.    any later version.
  9.  
  10.    This file is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.    GNU General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this file; if not, write to the Free Software
  17.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.    
  19. /*
  20.  * This time, we will only use the coff headers to tell the kernel
  21.  * how to exec the file.  Therefore, the only fields that need to 
  22.  * be filled in are the scnptr and vaddr for the text and data
  23.  * sections, and the vaddr for the bss.  As far as coff is concerned,
  24.  * there is no symbol table, relocation, or line numbers.
  25.  *
  26.  * A normal bsd header (struct exec) is placed after the coff headers,
  27.  * and before the real text.  I defined a the new fields 'a_machtype'
  28.  * and a_flags.  If a_machtype is M_386, and a_flags & A_ENCAP is
  29.  * true, then the bsd header is preceeded by a coff header.  Macros
  30.  * like N_TXTOFF and N_TXTADDR use this field to find the bsd header.
  31.  * 
  32.  * The only problem is to track down the bsd exec header.  The
  33.  * macros HEADER_OFFSET, etc do this.  Look at nm.c, dis.c, etc
  34.  * for examples.
  35.  */
  36.  
  37. #if !defined (A_OUT_ENCAP_H)
  38. #define A_OUT_ENCAP_H 1
  39.  
  40. #ifdef GNUDOS
  41. #include "aoutgnu.h"
  42. #else
  43. #include "a.out.gnu.h"
  44. #endif
  45.  
  46. #define N_FLAGS_COFF_ENCAPSULATE 0x20 /* coff header precedes bsd header */
  47.  
  48. /* Describe the COFF header used for encapsulation.  */
  49.  
  50. struct coffheader
  51. {
  52.   /* filehdr */
  53.   unsigned short f_magic;
  54.   unsigned short f_nscns;
  55.   long f_timdat;
  56.   long f_symptr;
  57.   long f_nsyms;
  58.   unsigned short f_opthdr;
  59.   unsigned short f_flags;
  60.   /* aouthdr */
  61.   short magic;
  62.   short vstamp;
  63.   long tsize;
  64.   long dsize;
  65.   long bsize;
  66.   long entry;
  67.   long text_start;
  68.   long data_start;
  69.   struct coffscn
  70.     {
  71.       char s_name[8];
  72.       long s_paddr;
  73.       long s_vaddr;
  74.       long s_size;
  75.       long s_scnptr;
  76.       long s_relptr;
  77.       long s_lnnoptr;
  78.       unsigned short s_nreloc;
  79.       unsigned short s_nlnno;
  80.       long s_flags;
  81.     } scns[3];
  82. };
  83.  
  84. /* Describe some of the parameters of the encapsulation,
  85.    including how to find the encapsulated BSD header.  */
  86.  
  87. #ifdef i386
  88. #define COFF_MAGIC 0514 /* I386MAGIC */
  89. #endif
  90. #ifdef m68k
  91. #define COFF_MAGIC 0520 /* MC68MAGIC */
  92. #endif
  93.  
  94. #ifdef COFF_MAGIC
  95. short __header_offset_temp;
  96. #define HEADER_OFFSET(f) \
  97.     (__header_offset_temp = 0, \
  98.      fread ((char *)&__header_offset_temp, sizeof (short), 1, (f)), \
  99.      fseek ((f), -sizeof (short), 1), \
  100.      __header_offset_temp==COFF_MAGIC ? sizeof(struct coffheader) : 0)
  101.  
  102. #define HEADER_OFFSET_FD(fd) \
  103.     (__header_offset_temp = 0, \
  104.      read ((fd), (char *)&__header_offset_temp, sizeof (short)), \
  105.      lseek ((fd), -sizeof (short), 1), \
  106.      __header_offset_temp==COFF_MAGIC ? sizeof(struct coffheader) : 0)
  107.  
  108.  
  109. #else
  110. #define HEADER_OFFSET(f) 0
  111. #define HEADER_OFFSET_FD(fd) 0
  112. #endif
  113.  
  114. #define HEADER_SEEK(f) (fseek ((f), HEADER_OFFSET((f)), 1))
  115. #define HEADER_SEEK_FD(fd) (lseek ((fd), HEADER_OFFSET_FD((fd)), 1))
  116.  
  117.  
  118. /* Describe the characteristics of the BSD header
  119.    that appears inside the encapsulation.  */
  120.  
  121. #undef _N_HDROFF
  122. #undef N_TXTADDR
  123. #undef N_DATADDR
  124.  
  125. #define _N_HDROFF(x) ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \
  126.               sizeof (struct coffheader) : 0)
  127.  
  128. /* Address of text segment in memory after it is loaded.  */
  129. #define N_TXTADDR(x) \
  130.     ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \
  131.      sizeof (struct coffheader) + sizeof (struct exec) : 0)
  132. #define SEGMENT_SIZE 0x400000
  133.  
  134. #define N_DATADDR(x) \
  135.     ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \
  136.      (SEGMENT_SIZE + ((N_TXTADDR(x)+(x).a_text-1) & ~(SEGMENT_SIZE-1))) : \
  137.      (N_TXTADDR(x)+(x).a_text))
  138. #endif /* a.out.encap.h not already included.  */
  139.